package napier.sadari;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.Spinner;
import android.widget.TextView;

public class SingleGameActivity extends Activity {
		
	Spinner spnBtn;
	Button singleStartBtn;
	long playerNumber;
	TextView p2_1;
	LinearLayout p3,p4,p5,p6,p7,p8;
	EditText p1_name, p2_name, p3_name, p4_name, p5_name, p6_name, p7_name, p8_name ;
	EditText p1_gift, p2_gift, p3_gift, p4_gift, p5_gift, p6_gift, p7_gift, p8_gift ;
	
	
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.single_activity);
        
        
        spnBtn = (Spinner)findViewById(R.id.singlePlayerNumberBtn);
        singleStartBtn = (Button)findViewById(R.id.singleStartBtn);
        p3 = (LinearLayout)findViewById(R.id.player3);
        p4 = (LinearLayout)findViewById(R.id.player4);
        p5 = (LinearLayout)findViewById(R.id.player5);
        p6 = (LinearLayout)findViewById(R.id.player6);
        p7 = (LinearLayout)findViewById(R.id.player7);
        p8 = (LinearLayout)findViewById(R.id.player8);
        
        p1_name = (EditText)findViewById(R.id.player1_name);
        p2_name = (EditText)findViewById(R.id.player2_name);
        p3_name = (EditText)findViewById(R.id.player3_name);
        p4_name = (EditText)findViewById(R.id.player4_name);
        p5_name = (EditText)findViewById(R.id.player5_name);
        p6_name = (EditText)findViewById(R.id.player6_name);
        p7_name = (EditText)findViewById(R.id.player7_name);
        p8_name = (EditText)findViewById(R.id.player8_name);
        
        
        p1_gift = (EditText)findViewById(R.id.player1_gift);
        p2_gift = (EditText)findViewById(R.id.player2_gift);
        p3_gift = (EditText)findViewById(R.id.player3_gift);
        p4_gift = (EditText)findViewById(R.id.player4_gift);
        p5_gift = (EditText)findViewById(R.id.player5_gift);
        p6_gift = (EditText)findViewById(R.id.player6_gift);
        p7_gift = (EditText)findViewById(R.id.player7_gift);
        p8_gift = (EditText)findViewById(R.id.player8_gift);
        
        
//        p2_1 = (TextView)findViewById(R.id.player2_1);
//        EditText p2_2 = (EditText)findViewById(R.id.player2_2);
//        EditText p2_3 = (EditText)findViewById(R.id.player2_3);
        
        setBtnAction();
    }    

	private void setBtnAction(){
		
		spnBtn.setOnItemSelectedListener(new OnItemSelectedListener() {
			
			public void onItemSelected(AdapterView<?> parent, View view, int position, long id){
				playerNumber = spnBtn.getSelectedItemId()+2;
				Log.e(" / ", ""+playerNumber);
				p3.setVisibility(LinearLayout.VISIBLE);
				p4.setVisibility(LinearLayout.VISIBLE);
				p5.setVisibility(LinearLayout.VISIBLE);
				p6.setVisibility(LinearLayout.VISIBLE);
				p7.setVisibility(LinearLayout.VISIBLE);
				p8.setVisibility(LinearLayout.VISIBLE);
				
				switch((int)playerNumber){
				case 2:
					p3.setVisibility(LinearLayout.GONE);					
				case 3:
					p4.setVisibility(LinearLayout.GONE);					
				case 4:
					p5.setVisibility(LinearLayout.GONE);
				case 5:
					p6.setVisibility(LinearLayout.GONE);
				case 6:
					p7.setVisibility(LinearLayout.GONE);
				case 7:
					p8.setVisibility(LinearLayout.GONE);
					break;
				}
			}
			
			public void onNothingSelected(AdapterView<?> parent){
				
			}
			
		});	
		
		singleStartBtn.setOnClickListener(new OnClickListener(){
        	public void onClick(View v){        		
        		Intent aIntent = new Intent(SingleGameActivity.this, DrawSadariActivity.class);
        		aIntent.putExtra("playerNumber", playerNumber);
        		        		
        		String[] playersName = new String[9];
        		String[] playersGift = new String[9];
        		
        		playersName[1] = p1_name.getText().toString();
        		playersGift[1] = p1_gift.getText().toString();
        		playersName[2] = p2_name.getText().toString();
        		playersGift[2] = p2_gift.getText().toString();
        		playersName[3] = p3_name.getText().toString();
        		playersGift[3] = p3_gift.getText().toString();
        		playersName[4] = p4_name.getText().toString();
        		playersGift[4] = p4_gift.getText().toString();
        		playersName[5] = p5_name.getText().toString();
        		playersGift[5] = p5_gift.getText().toString();
        		playersName[6] = p6_name.getText().toString();
        		playersGift[6] = p6_gift.getText().toString();
        		playersName[7] = p7_name.getText().toString();
        		playersGift[7] = p7_gift.getText().toString();
        		playersName[8] = p8_name.getText().toString();
        		playersGift[8] = p8_gift.getText().toString();
        		
        		aIntent.putExtra("playersName", playersName);
        		aIntent.putExtra("playersGift", playersGift);
        	
        	
        	
        		startActivity(aIntent);
        	}
        });
		
		
	}// end of setBtnAction()
	
}